﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZhongheCms.Models;

namespace ZhongheCms.Controllers
{
    public class CustomerMsgController : Controller
    {
        public ActionResult Index(int id = 0, string m = "", string f = "", string p = "", string fid = "", string sdate = "", string edate = "", string keywords = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
            ViewBag.keywords = keywords;
            ViewBag.sdate = sdate;
            ViewBag.edate = edate;
            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;
            var news = GswTblMsg.GetMsgList(sdate, edate, keywords, fid, GswTblUser.CurrentUser.CustomerId);
           
            return View(news);
        }

        public ActionResult Create(int id = 0, string m = "", string f = "", string p = "", string fid = "", string sdate = "", string edate = "", string keywords = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
            ViewBag.keywords = keywords;
            ViewBag.sdate = sdate;
            ViewBag.edate = edate;
            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;
            var news = GswTblMsg.SingleOrDefault(id);
           
            return View(news);

        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Create(int id, FormCollection c, string m = "", string f = "", string p = "", string fid = "", string sdate = "", string edate = "", string keywords = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
            ViewBag.keywords = keywords;
            ViewBag.sdate = sdate;
            ViewBag.edate = edate;
            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;
            try
            {
                GswTblMsg.Update("set ReFlag=1,ReMsg='" + c["ReMsg"] + "' where id=" + id);
                ViewBag.scode = "suc";
            }
            catch (Exception e)
            {
                ViewBag.scode = "err";
                ModelState.AddModelError(string.Empty, e.Message);
            }
           
            var news = GswTblMsg.SingleOrDefault(id);
            return View(news);
        }

        public ActionResult Delete(int id, string m = "", string f = "", string p = "", string fid = "", string sdate = "", string edate = "", string keywords = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
            ViewBag.keywords = keywords;
            ViewBag.sdate = sdate;
            ViewBag.edate = edate;
            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;
            GswTblMsg.Delete("WHERE Id=" + id);
            var qry = GswTblMsg.GetMsgList(sdate, edate, keywords, fid, GswTblUser.CurrentUser.CustomerId);
           
            return View("Index", qry);
        }


    }
}
